#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct ListNode
{
    int val;
    struct ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};

//删除链表中重复的结点
ListNode *deleteDuplication(ListNode *pHead)
{
    if (!pHead)
    {
        return pHead;
    }
    ListNode *p0 = new ListNode(0); //伪头
    p0->next = pHead;
    ListNode *p1, *p2;
    p1 = p0;
    p2 = pHead->next;
    while (p2)
    {
        if (p1->next->val == p2->val)
        {
            while (p2 && p1->next->val == p2->val)
            {
                p2 = p2->next;
            }
            p1->next = p2;
            if (p2)
            {
                p2 = p2->next;
            }
            else
            {
                break;
            }
        }
        else
        {
            p1 = p1->next;
            p2 = p2->next;
        }
    }
    p1 = p0->next;
    delete p0; //防止堆内存泄漏
    return p1;
}

void test()
{
}

int main()
{
    test();
    return 0;
}